import { Provide } from '@midwayjs/core';
import { prisma } from '../prisma';

@Provide()
export class UserService {
  async getUser(uid: string) {
    return prisma.user.findFirst({
      where: { id: uid, deleted: false },
      select: {
        id: true,
        username: true,
        email: true,
        createdAt: true,
        updatedAt: true,
      },
    });
  }
  async findUser(username: string) {
    return await prisma.user.findFirst({ where: { username } });
  }
  async create(user: UserCreateModel) {
    return await prisma.user.create({ data: user });
  }
}
export interface UserCreateModel {
  username: string;
  password: string;
  salt: string;
}
